package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AddressBookMapper {
    /**
     * 添加地址
     * @param addressBook
     */
    @Insert("insert into address_book values (null,#{userId},#{consignee} ,#{sex} ,#{phone} ,#{provinceCode} ,#{provinceName} ,#{cityCode} " +
            ",#{cityName} ,#{districtCode} ,#{districtName} ,#{detail} ,#{label} ,0 )")
    void save(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(Long userId);

    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook def(Long userId);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id} ")
    void del(Long id);

    @Select("select * from address_book where id = #{id} ")
    AddressBook findById(Long id);

    @Update("update address_book set is_default = 0 where  user_id = #{userId} ")
    void updSet0(long userId);
}
